<?php
$updateSuccess= 0;
if(isset($_POST['chagepwd']) && $_POST['chagepwd'] == 'update')
{
	$currentpassword = $_POST['currentpassword'];
	$newpassword = $_POST['newpassword'];
	$confirmpassword = $_POST['confirmpassword'];
	/*$Mobile = $_POST['Mobile'];
	$Phone = $_POST['Phone'];
	$Email = $_POST['Email'];*/


$sql = "SELECT * FROM `client_logininfo` WHERE password = '".md5($currentpassword)."' AND CurrentContact_id = ".$_SESSION['CurrentContact_id'].";";
/*echo $currentpassword;
echo '<br />'; 
echo $sql; exit;*/
if($result = mysql_query($sql)){
	if(mysql_num_rows($result) > 0)
	{
		$sql = "UPDATE client_logininfo SET password = '".md5($newpassword)."' WHERE CurrentContact_id = ".$_SESSION['CurrentContact_id'];
		if(!mysql_query($sql))
		{
			
			$_SESSION['pwd_msg'] = 'Current password is NOT right.';
		}else{
			$updateSuccess= 1;
		}
	} 
}
else
	$_SESSION['pwd_msg'] = 'Current password is NOT right.';
	

if (isset($_SESSION['pwd_msg'])) {
 echo '<div class="passwordNotcurrect">' . $_SESSION['pwd_msg'] . '</div>';
 $_SESSION['pwd_msg'] = '';
}
}

if(isset($_POST['submit']) && $_POST['submit'] == 'update')
{
	$Mobile = $_POST['Mobile'];
	$Phone = $_POST['Phone'];
	$Email = $_POST['Email']; 
	
		//$sql = "UPDATE client_logininfo SET email_address = '".$Email."' WHERE CurrentContact_id = ".$_SESSION['CurrentContact_id'];
		//mysql_query($sql);
		//echo $sql; exit;
$sql = "UPDATE crm_contact SET Mobile = '".$Mobile."', HomePhone = '".$Phone."', Email = '".$Email."' WHERE ContactID = ".$_SESSION['applicant_id'];
		mysql_query($sql);
		//echo $sql; exit; 
	} 

?>

<div class="profile"> 
  <ul class="nav nav-pills nav-justified" id="myTab">
    <li class="info"><a href="#credential_info" data-toggle="tab">Change Password</a></li>
    <li class="personal"><a href="#personal_info" data-toggle="tab">Personal Info</a></li>
  </ul>
  <div class="tab-content">
    <div class="tab-pane active" id="credential_info">
      <form id="formProfile" action="<?php // echo $_SERVER['PHP_SELF'];?>?profile" method="post" class="form-vertical">
        <fieldset class="scheduler-border">
          <legend class="scheduler-border">Change Password</legend>
          <div class="control-group">
            <label class="control-label" for="inputEmail">Current Password</label>
            <div class="controls">
              <input type="password" id="currentpassword" name="currentpassword" placeholder="Password" class="span5 checkPwdClass required">
            </div>
          </div>  
          <div class="control-group">
            <label class="control-label" for="inputPassword">New Password</label>
            <div class="controls">
              <input type="password" id="newpassword" name="newpassword" placeholder="Password" class="span5 required">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="inputPassword">Confirm New Password</label>
            <div class="controls">
              <input type="password" id="confirmpassword" name="confirmpassword" placeholder="Password" class="span5 required">
            </div>
            <div id="passwordNotMatch" style="color:#F00; float:left"></div><br />
          </div>
          <input type="submit" name="chagepwd" class="btn btn-green " id="chagepwd" value="update"/>
        </fieldset>
      </form>
    </div>

  <div class="modal hide fade" id="successModal">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h3>Change Password</h3>
  </div>
  <div class="modal-body">
    <p>Password has been changed successfully</p>
  </div>
  <div class="modal-footer">
    <a href="#" class="btn" data-dismiss="modal" aria-hidden="true">Close</a>
    <a href="index.php?dashboard" class="btn btn-primary">OK</a>
  </div>
</div>
    <div class="tab-pane" id="personal_info">
      <form id="formPersonal" action="<?php // echo $_SERVER['PHP_SELF'];?>?profile" method="post" class="form-vertical">
        <fieldset class="scheduler-border">
          <legend class="scheduler-border">Update Contacts</legend>
          <div class="control-group">
            <label class="control-label" for="inputMobile">Mobile</label>
            <div class="controls">
              <input type="text" id="inputMobile" placeholder="Mobile" name="Mobile" class="span5 Mobile uniqueMobileClass required">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="inputPhone">Phone</label>
            <div class="controls">
              <input type="text" id="inputPhone" placeholder="Phone" name="Phone" class="span5 Phone uniquePhoneClass required">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="inputEmail">Email</label>
            <div class="controls">
              <input type="text" id="inputEmail" placeholder="Email" name="Email" class="span5 Email uniqueEmailClass required">
            </div>
          </div>
         <input type="submit" name="submit" class="btn btn-green " id="personal" value="update"/>
        </fieldset>
      </form>
    </div>
  </div>
</div>
</div>
<script>
		  
		  $(document).ready(function(){
		<?php if($updateSuccess): 
		
		?>
		
		$('#successModal').modal('show'); 
		<?php endif; ?>
	$( "#confirmpassword" ).focusout(function(){
		var password=$('#newpassword').val();
		var confirmpassword=$('#confirmpassword').val();
		if(password!=confirmpassword)
		{
			$("#passwordNotMatch").text("New & Confirm password is NOT match.");
			$("#passwordNotMatch").show();
			document.getElementById("chagepwd").disabled=true;
			return false;
		}
		else 
		{
			$("#passwordNotMatch").hide(); 
			document.getElementById("chagepwd").disabled=false;
		}
	});	
	
});

		  
/*$(document).ready(function(){
	$( "#chagepwd" ).click(function(){
																				
		var password=$('#newpassword').val();
		var confirmpassword=$('#confirmpassword').val();
		if(password!=confirmpassword)
		{
			$("#passwordNotMatch").text("New & Confirm password is NOT match.");
			$("#passwordNotMatch").show();
			return false;
		}
		else 
		{
			$("#passwordNotMatch").hide();
		}
	});	
	
});*/


$(function () {
    $('#myTab a:first').tab('show')
  })
</script>
